package cn.com.digitalnet.ad.base;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.Specification;
import org.springside.modules.persistence.DynamicSpecifications;
import org.springside.modules.persistence.SearchFilter;

import cn.com.digitalnet.ad.search.SearchFilterBuilder;
import cn.com.digitalnet.ad.util.EhcacheUtil;

public class BaseService {
	
	/**
	 * 创建动态查询条件组合
	 * @author qidafang
	 * @param searchParams 查询条件的键值对
	 * @param         要查询的实体类
	 * @return
	 */
	protected <T> Specification<T> buildSpecification(Map<String, Object> searchParams,Class<T> clazz) {
		Map<String, SearchFilter> filters = SearchFilterBuilder.build(searchParams);
		Specification<T> spec = DynamicSpecifications.bySearchFilter(filters.values(), clazz);
		return spec;
	}

	@Autowired protected EhcacheUtil ehcacheUtil;
}
